package com.teamwork.ZuccEcho.Entity;

import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.List;
import java.util.Set;

////学生
//@Entity
//@Table(name = "Student", schema = "", catalog = "")
//public class Student {
//    private String stuId;//学号(唯一)
//    private String sPwd;//密码，初始123456
//    private String phone;//手机号（登录或者找回密码用）
//    private String college;//学院名称
//    private String grade;//年级
//    private String sName;//姓名
//    private List<AnswerSheet> answerSheets;//所有反馈
//    private List<Info> sInfo;//所有系统通知
////    private List<Class> classes;//教学班
//
//    @Id
//    @Column(name = "stuId")
//    @GeneratedValue(strategy = GenerationType.AUTO)
//    public String getStuId() {
//        return stuId;
//    }
//
//    public void setStuId(String stuId) {
//        this.stuId = stuId;
//    }
//
//    @Basic
//    @Column(name = "sPwd")
//    public String getsPwd() {
//        return sPwd;
//    }
//
//    public void setsPwd(String sPwd) {
//        this.sPwd = sPwd;
//    }
//
//    @Basic
//    @Column(name = "phone")
//    public String getPhone() {
//        return phone;
//    }
//
//    public void setPhone(String phone) {
//        this.phone = phone;
//    }
//
//    @Basic
//    @Column(name = "college")
//    public String getCollege() {
//        return college;
//    }
//
//    public void setCollege(String college) {
//        this.college = college;
//    }
//
//    @Basic
//    @Column(name = "grade")
//    public String getGrade() {
//        return grade;
//    }
//
//    public void setGrade(String grade) {
//        this.grade = grade;
//    }
//
//    @Basic
//    @Column(name = "sName")
//    public String getsName() {
//        return sName;
//    }
//
//    public void setsName(String sName) {
//        this.sName = sName;
//    }
//
//    @Override
//    public boolean equals(Object o) {
//        if (this == o) return true;
//        if (o == null || getClass() != o.getClass()) return false;
//        Student that = (Student) o;
//        return stuId == that.stuId &&
//                Objects.equals(sPwd, that.sPwd) &&
//                Objects.equals(phone, that.phone) &&
//                Objects.equals(college, that.college) &&
//                Objects.equals(grade, that.grade) &&
//                Objects.equals(sName, that.sName);
//    }
//
//    @Override
//    public int hashCode() {
//        return Objects.hash(stuId, sPwd, phone, college, grade, sName);
//    }
//}

//学生
@Entity
@Getter
@Setter
public class Student implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @NotBlank(message = "账号不能为空")
    private String stu_id;//学号(唯一)
    @NotBlank(message = "密码不能为空")
    private String stu_pwd;//密码，初始123456
    @NotBlank(message = "手机号不能为空")
    private String stu_phone;//手机号（登录或者找回密码用）
    private String stu_college;//学院名称
    private String stu_grade;//年级
    private String stu_name;//姓名

//    @OneToMany()
    @OneToMany(mappedBy = "student")
//    @JoinColumn(name="stu_id")//在子表中的外键名
    private List<Answersheet> answersheetList;

////    @OneToMany()
//    @OneToMany(mappedBy = "student")
////    @JoinColumn(name="stu_id")//在子表中的外键名
//    private List<Info> infoList;

    @ManyToMany(fetch=FetchType.LAZY)
    @JoinTable(name="course_student"
            ,joinColumns={@JoinColumn(name="stu_id")}
            ,inverseJoinColumns={@JoinColumn(name="c_id")})
    private Set<Course> courses;

    @Override
    public String toString() {
        return "Student{" +
                "stu_id='" + stu_id + '\'' +
                ", stu_pwd='" + stu_pwd + '\'' +
                ", stu_phone='" + stu_phone + '\'' +
                ", stu_college='" + stu_college + '\'' +
                ", stu_grade='" + stu_grade + '\'' +
                ", stu_name='" + stu_name + '\'' +
                '}';
    }
}
